//
//  HMStatusListViewModel.swift
//  VVeibo21
//
//  Created by apple on 2016/10/27.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit
import YYModel

class HMStatusListViewModel: NSObject {

    var dataArray:[HMStatusViewModel] = [HMStatusViewModel]()
    
    func getHomeData(finish:@escaping (Bool)->()){
        HMNetworkTools.sharedTools.homeLoadData(success: { (response) in
//            print("")
            guard let resDict = response as? [String:Any] else{
                finish(false)
                return
            }
            guard let resArr = resDict["statuses"] as? [[String:Any]] else{
                finish(false)
                return
            }
            let statusArray = NSArray.yy_modelArray(with: HMStatusModel.self, json: resArr) as! [HMStatusModel]
            
            var tempArray:[HMStatusViewModel] = [HMStatusViewModel]()
            
            for model in statusArray{
                let statusViewModel = HMStatusViewModel()
                statusViewModel.statusModel = model
                tempArray .append(statusViewModel)
            }
            
            self.dataArray = tempArray
            finish(true)
            
            }) { (error) in
                print("请求失败",error)
                finish(false)
        }
    }
    
}
